package com.veeder.datacollection.rs232.comm;

import java.net.InetSocketAddress;

import com.veeder.datacollection.config.ConnectionParam;
import com.veeder.datacollection.config.ConnectionParam.ConnectionMode;
import com.veeder.datacollection.config.SerialPortParam;

/**
 * Connection Factory responds for creating the specific connection.
 * @author txing
 *
 */
public class ConnectionFactory {
	
	public static Connection getConnection(ConnectionParam param, int connnectTimeout, int readTimeout){
		ConnectionMode mode =param.getMode();
		Connection connection = null;
		switch(mode){
		case TCPIP:
			InetSocketAddress hostSocketAddress =param.getHostSocketAddress();
			connection = new TCPConnection(hostSocketAddress,connnectTimeout, readTimeout);	
			break;
			
		case SerialCommunication:
			SerialPortParam serialParam =param.getSerialParam();
			connection = new SerialConnection(serialParam,connnectTimeout, readTimeout);
			break;
		default:
			break;
		
		}		
		return connection;
		
	}

}
